﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.Office.Interop.Word;
using NET.Tools;
using Puzzler.Plugin.Interface;
using Puzzler.Plugin.Interface.Attributes;

namespace Plugin.Default.SwedenGrid
{
    [PuzzleWordAddInHandler]
    public sealed class SwedenGridWordAddInHandler : GridPuzzleWordAddInHandler<SwedenGridModel, SwedenGridCellInfo>
    {
        public SwedenGridWordAddInHandler(SwedenGridModel model) : base(model)
        {
        }

        public override void AddGameContent(Range range, IList<Canvas> images)
        {
            if (images.Count != 1)
                throw new ArgumentException("Internal Error");

            string tmpFile = Path.GetTempFileName();
            using (FileStream fs = new FileStream(tmpFile, FileMode.Create))
            {
                images[0].SaveAsImage(fs, BitmapEncoding.Png);
            }

            range.InlineShapes.AddPicture(tmpFile);
        }

        public override void AddSolutionContent(Range range, IList<Canvas> images)
        {
            if (images.Count != 1)
                throw new ArgumentException("Internal Error");

            string tmpFile = Path.GetTempFileName();
            using (FileStream fs = new FileStream(tmpFile, FileMode.Create))
            {
                images[0].SaveAsImage(fs, BitmapEncoding.Png);
            }

            range.InlineShapes.AddPicture(tmpFile);
        }
    }
}
